<template>
  <div>
    <section class="header clearfix">
      <span>人员管理</span>
    </section>
    <div class="search-box" @keyup.enter="searchFun">
      <i class="iconfont iconsearch1"></i>
      <el-input
        placeholder="输入身份证进行搜索"
        class="search"
        v-model.trim="idCardNo"
        clearable
      ></el-input>
    </div>
    <div class="search-box search-box-last">
      <section class="option">
        <span>参保单位:</span>
        <el-select v-model="platformId" @change="getData" placeholder="请选择">
          <el-option
            v-for="item in platformOptions"
            :key="item.platformId"
            :label="item.platformName"
            :value="item.platformId"
          ></el-option>
        </el-select>
      </section>
    </div>
    <div class="table">
      <el-table
        :data="tableData"
        v-loading="loading"
        tooltip-effect="dark"
        style="width: 100%"
      >
        <el-table-column
          prop="platformName"
          fixed
          label="参保单位"
          :formatter="valueFormatter"
        ></el-table-column>
        <el-table-column
          prop="privatePlatformName"
          fixed
          label="修正参保单位"
          :formatter="valueFormatter"
        ></el-table-column>
        <el-table-column
          prop="fullName"
          fixed
          label="姓名"
          :formatter="valueFormatter"
        ></el-table-column>
        <el-table-column
          prop="sex"
          label="性别"
          :formatter="sexFormatter"
        ></el-table-column>
        <el-table-column
          prop="phone"
          label="手机号"
          :formatter="valueFormatter"
        ></el-table-column>
        <el-table-column
          prop="idCard"
          label="身份证"
          :formatter="valueFormatter"
        ></el-table-column>
        <el-table-column
          prop="companyName"
          label="公司名称"
          :formatter="valueFormatter"
        ></el-table-column>
        <el-table-column label="操作" v-if="isShow">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              @click="getPlatform_dialog(scope.row.personId,scope.row.privatePlatformName)"
              >设置缴纳平台</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="current"
        :page-sizes="[6, 12, 24, 36]"
        :page-size="pageSize"
        layout="sizes, prev, pager, next"
        :total="total"
      ></el-pagination>
    </div>
    <!--选择缴纳平台-->
    <el-dialog
      title="选择缴纳平台"
      :visible.sync="dialogPlatformId"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :show-close="false"
      width="350px"
      height="400px"
      center
    >
      <el-form>
        <el-form-item label="平台" label-width="80px" required>
          <el-select v-model="pId" placeholder="请选择">
            <el-option
              v-for="item in platformOptions"
              :key="item.platformId"
              :label="item.platformName"
              :value="item.platformId"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogPlatformId = false">取 消</el-button>
        <el-button type="primary" @click="comfirmPlatform">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
  <script>
import { requestApiPost } from "../api/api";
import { reqRep } from "../report/reqReport";
import { resRep } from "../report/resReport";
import JsonExcel from "vue-json-excel";
import base from "../assets/js/base";
export default {
  name: "userManagement",
  data() {
    return {
      isShow:true,
      date: "",
      platformId: "",
      excelName: "",
      inOutJobStatus: "0",
      idCardNo: "",
      isDisabled: true,
      loading: false,
      outInutLoading: false,
      dialogPlatformId: false,
      disposeArr: [],
      total: null,
      current: 1,
      switchIndex: 0,
      pageSize: 6,
      pId:null,
      personId:null,
      menu: [
        { title: "未处理", value: "0" },
        { title: "已通过", value: "1" },
        { title: "未通过", value: "2" },
      ],
      //是否入职或离职审核 0无；1入职；2离职
      typeOptions: [
        {
          value: "0",
          label: "全部",
        },
        {
          value: "1",
          label: "新增",
        },
        {
          value: "2",
          label: "停缴",
        },
      ],
      platformOptions: [], //参保单位
      excelData: [],
      tableData: [],
    };
  },
  methods: {
    handleCurrentChange(e) {
      this.current = e;
      this.getData();
    },
    handleSizeChange(e) {
      this.pageSize = e;
      this.getData();
    },
    searchFun() {
      this.current = 1;
      this.getData();
    },
    //获取数据
    getData() {
      this.loading = true;
      var reqData = {
        idCardNo: this.idCardNo,
        platformId: this.platformId,
        current: this.current,
        pageSize: this.pageSize,
      };
      let reqReport = reqRep({ traCode: "_LIST_PERSON_V2_2", data: reqData });
      requestApiPost(reqReport).then((data) => {
        let resReport = resRep(data);
        this.loading = false;
        if (resReport.getReCode() != "0000") {
          this.$message({
            message: resReport.getReMsg(),
            type: "error",
          });
        } else {
          this.tableData = resReport.data.records || [];
          this.total = parseInt(resReport.data.total);
        }
      });
    },
    //确认平台
    comfirmPlatform() {
      if (!this.pId) {
        this.$message.warning("请选择平台");
        return;
      }
      this.loading = true;
      var reqData = {
        personId: this.personId,
        platformId: this.pId,
      };
      let reqReport = reqRep({ traCode: "_SAVE_PAY_PLATFORM", data: reqData });
      console.log(reqReport);
      requestApiPost(reqReport).then((data) => {
        let resReport = resRep(data);
        this.loading = false;
        if (resReport.getReCode() != "0000") {
          this.$message({
            message: resReport.getReMsg(),
            type: "error",
          });
        } else {
          this.personId=null;
          this.pId=null;
          this.dialogPlatformId = false;
          this.getData();
        }
      });
    },
    //获取参保单位
    getPlatform_dialog(personId,privatePlatformName) {

      this.personId=personId;
      this.pId=privatePlatformName==undefined||privatePlatformName==null?null:privatePlatformName;
      this.dialogPlatformId = true;
      // var reqData = {
      //   current: 1,
      //   pageSize: 999,
      // };
      // let reqReport = reqRep({ traCode: "_LIST_PAY_PLATFORM", data: reqData });
      // requestApiPost(reqReport).then((data) => {
      //   let resReport = resRep(data);
      //   if (resReport.getReCode() != "0000") {
      //     this.$message({
      //       message: resReport.getReMsg(),
      //       type: "error",
      //     });
      //   } else {
      //     this.platformOptions = resReport.data.records;
          
      //   }

      // });
    },
    //获取参保单位
    getPlatform() {
      var reqData = {
        current: 1,
        pageSize: 999,
      };
      let reqReport = reqRep({ traCode: "_LIST_PAY_PLATFORM", data: reqData });
      requestApiPost(reqReport).then((data) => {
        let resReport = resRep(data);
        if (resReport.getReCode() != "0000") {
          this.$message({
            message: resReport.getReMsg(),
            type: "error",
          });
        } else {
          this.platformOptions = resReport.data.records;
        }
      });
    },
    sexFormatter(a, b, c) {
      if (c == 1) {
        return "男";
      } else if (c == 2) {
        return "女";
      } else {
        return "未知";
      }
    },
    valueFormatter(a, b, c) {
      if (c) {
        return c;
      } else {
        return "-";
      }
    },
  },
  filters: {},

  created() {
    this.getData();
    this.getPlatform();
  },
};
</script>
  <style scoped>
.header {
  padding: 15px;
  height: 50px;
  box-sizing: border-box;
  font-size: 14px;
  border-bottom: 1px solid #eee;
}
.header .org {
  float: right;
  cursor: pointer;
}
.org:hover {
  color: #13cb6e;
}
.header i {
  margin-right: 5px;
}
.opt-user {
  padding: 20px 15px;
}
.opt-user > section {
  display: inline-block;
  margin-right: 20px;
  cursor: pointer;
}
.opt-user i {
  font-size: 20px;
  margin-right: 5px;
  vertical-align: middle;
}
.opt-user .iconadd1 {
  color: #13cb6e;
}
.opt-user .iconbiaoge-xiazai {
  color: #33ac37;
}
.add-user:hover {
  color: #13cb6e;
}
.input-user:hover {
  color: #33ac37;
}
.menu-swtich {
  height: 50px;
  line-height: 50px;
  border-bottom: 1px solid #eee;
}
.menu-swtich li {
  display: inline-block;
  padding: 0 15px;
  cursor: pointer;
}
.menu-swtich .el-button {
  margin-top: 5px;
  float: right;
  margin-right: 10px;
}

.active {
  color: #13cb6e;
  border-bottom: 2px solid #13cb6e;
}
.search-box {
  height: 50px;
  line-height: 50px;
  border-bottom: 1px solid #eee;
}
.search-box-last {
  border-top: none;
}
.search-box i {
  margin-left: 15px;
  vertical-align: middle;
}
.search-box .search {
  display: inline-block;
  width: calc(100% - 36px);
}
.search-box .option {
  display: inline-block;
  margin-left: 15px;
}
.search-box .el-select {
  width: 150px;
}
.search-box .el-select input {
  min-width: 100px;
  background-color: #eee;
}
.search-box .batchChange {
  display: inline-block;
  color: #999;
  font-size: 14px;
  cursor: pointer;
}

.showMoney {
  padding: 15px;
}
.showMoney .sm-h {
  margin-bottom: 40px;
}
.sm-h section {
  display: inline-block;
  margin-right: 20px;
}
.sm-h .month {
  margin-left: 10px;
  color: #999;
}
i {
  color: #999;
  font-size: 16px;
}
.download {
  float: right;
  font-size: 14px;
  margin-right: 0 !important;
}
.sm-f > ul {
  display: inline-block;
  width: 100px;
  margin-right: 15px;
  color: #666;
}
.sm-f .value {
  color: #666;
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 5px;
}
.sm-f .button {
  float: right;
  width: 140px;
  text-align: center;
  height: 50px;
  font-size: 20px;
  line-height: 50px;
  color: #fff;
  border-radius: 4px;
  background-color: #13cb6e;
}
.table {
  margin-top: 4px;
}
.table .content {
  display: inline-block;
  border-right: 1px solid #ccc;
}
.table .content:last-child {
  border: none;
}
.table .content > section {
  padding: 10px 15px;
}
.table .content > section span {
  margin-right: 10px;
  display: inline-block;
  width: 80px;
  color: #999;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.table .content > section span:nth-child(2) {
  text-align: center;
}
.table .content > section span:last-child {
  margin-right: 0;
  text-align: center;
}
.rests {
  float: right;
}
</style>
  